	<?php
		include("gen.php");
		$cmd=get_datan("cmd");
		switch($cmd){
			case 1:
				//get one vaccine based on id
				get_all_community_members();
			break;
				
			case 2:
				delete_community_member();		
			break;
				
			case 3:		
			//get the data from url / request and update the vaccine record
			update_community_members();
			break;
			
			default:
				echo "{";
				echo jsonn("result",0). ",";
				echo jsons("message","unknown command");
				echo "}";
		}
		
		
		function get_all_community_members(){
			include_once("community_members2.php");
			
			$community_member_id=get_datan("community_member_id");
			$v=new community_members2();
			$v->get_a_community_member($community_member_id);
			$row = $v->fetch();
			if(!$row){
				echo "{";
				echo jsonn("result",0). ",";
				echo jsons("message","community member not found");
				echo "}";
				return;
			}
			
				echo "{";
				echo jsonn("result",1) .",";
				echo "\"community_member\":{";
				echo jsonn("community_member_id",$row['community_member_id']) .",";
				echo jsons("card_number",$row['card_number']) .",";
				echo jsons("fullname",$row['fullname']) .",";
				echo jsonn("age",$row['age']) .",";
				echo jsons("birthdate",$row['birthdate']) .",";
				echo jsons("gender",$row['gender']) .",";
				echo jsonn("household_id",$row['household_id']) .",";
				echo jsonn("community_id",$row['community_id']) .",";
				echo jsons("registration_date",$row['registration_date']) .",";
				echo jsons("up_datedate",$row['up_datedate']) .",";
				echo jsonn("device_id",$row['device_id']);
				echo "}";
				echo "}";
			}


		function update_community_members(){
			$community_member_id=get_datan("community_member_id");
			$card_number=get_data("cn");
			$fullname=get_data("fn");
			$age=get_datan("age");
			$birthdate=get_data("bd");
			$gender=get_data("gd");
			$household_id=get_datan("hi");
			$community_id=get_datan("ci");
			$registration_date=get_data("rd");
			$up_datedate=get_data("ud");
			$device_id=get_datan("di");
			if(!$community_member_id){
			echo jsons("message","community member not found"); 
			//return an error message
			return;
		}
			include_once("community_members2.php");
			$v=new community_members2();
		
			if(!$v->update_community_members($community_member_id,$card_number,$fullname,$age,$birthdate,$gender,$household_id,$community_id,$registration_date,$up_datedate,$device_id)){
			echo "{";
			echo jsonn("result",0). ",";
			echo jsons("message", "error updating");
			echo "}";
			}else{
			echo "{";
			echo jsonn("result",0). ",";
			echo jsons("message", "updated");
			echo "}";
			}
		}
		
					
			function delete_community_member(){
			
			include_once("community_members2.php");
			$community_member_id=get_datan("community_member_id");
			$v=new community_members2();
			
			if(!$v->delete_community_member($community_member_id)){
			echo "{";
			echo jsonn("result",0). ",";
			echo jsons("message", "error deleting");
			echo "}";
			}else{
			echo "{";
			echo jsonn("result",0). ",";
			echo jsons("message", "deleted");
			echo "}";
			}
			
			}
			
		
		
	?>